package ex9;

import java.util.Scanner;

class ArrayUtils {
	public static double findMax(double[] arr,int begin, int end) throws IllegalArgumentException {
		if (begin >= end) {
			throw new IllegalArgumentException("begin:" + begin + " >= end:" + end);
		} else if (begin < 0) {
			throw new IllegalArgumentException("begin:" + begin + " < 0");
		} else if (end > arr.length) {
			throw new IllegalArgumentException("end:" + end + " > arr.length");
		} else {
			double res = arr[begin];
			for (int i = begin + 1; i < end; i++) {
				if (arr[i] > res) {
					res = arr[i];
				}
			}
			return res;
		}
	}
}
public class Test3 {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		double[] a = new double[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextDouble();
		}
		scanner.nextLine();
		while (true) {
			String string = scanner.nextLine();
			String[] strings = string.split(" ");
			try {
				System.out.println(
						ArrayUtils.findMax(
								a, 
								Integer.parseInt(strings[0]), 
								Integer.parseInt(strings[1])));
			} catch (Exception e) {
				if (e.getClass().equals(NumberFormatException.class)) {
					break;
				}
				System.out.println(e);
			}
		}
		
		
		
		try {
		     System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
		} catch (Exception e1) {
		}
		scanner.close();
	}
}
